<?php


namespace app\admin\service;

use think\facade\Queue;
use think\Model;

class NoticeTmp extends Model
{

    /**
     * $notice_result  notice_tmp查询信息
     * data  = [
     *  'tmp_flag' => 'system', 模板标识
        'to_user_id'   => 0, 收件人
        'from_user_id'   => 2, 发件人 系统消息0
        'content' => [
            'data' => 'xxx订单以投入生产'  //data 将末班中#data# 替换为 “xxx订单以投入生产“
        ]
     * ]
     * Desc: 根据模板发送信息
     * User: 苏鹏
     * Date: 2023/10/11
     * Time: 22:33
     * @return void
     */
    public function byTmpSendNotice(int $type, array $notice_result, array $data)
    {

        switch($type){
            case 1: //站内信
                $data['send_content'] = $this->handleInmailContent($notice_result['inmail_content'], $data['content']);
                //加入队列
                $data = [
                    'm' => 'app\admin\model\Notice',
                    'a' => 'sendInmail',
                    'param' =>$data
                ];
                Queue::push('app\job\DailyTasks',  $data, 'queueDailyTasks');
                break;
            case 2: //小程序

                break;
            case 3: //短信

                break;
            case 4: //邮件

                break;
        }

    }

    /**
     * $inmail_content 模板信息
     * Desc: 替换#xxx#数据
     * User: 苏鹏
     * Date: 2023/10/11
     * Time: 22:46
     * @return void
     */
    public function handleInmailContent(string $inmail_content, array $content) :string
    {
        foreach($content as $k=>$v){
            $result = str_replace('#'.$k.'#', $inmail_content, $v);
        }
        return $result;
    }
}